package com.dzu.easy;

import java.util.Arrays;

/**
 * @author ZhaoDong
 * @date 2022/12/26 9:47
 * @description 724. 寻找数组的中心下标
 */
public class Test724 {
    public static void main(String[] args) {
        System.out.println(pivotIndex(new int[]{1, 7, 3, 6, 5, 6}));
    }

    public static int pivotIndex(int[] nums) {

        int left = 0;
        int right = Arrays.stream(nums).sum();

        for (int i = 0; i < nums.length; i++) {
            right -= nums[i];
            if (left == right) {
                return i;
            }
            left += nums[i];
        }

        return -1;
    }
}
